<template>
    <view class="cart-item-product" :class="{ oneSpec: getAppSet().isOneSpec }" @click="goDetailPage()">
        <image v-if="!getAppSet().isHideImg" class="item-img" mode="aspectFill"
            :src="easyGetImgUrl(productInfo.V_ThumbnailUrl160)"></image>
        <text class="item-name">{{ productInfo.V_Title }}</text>
    </view>
</template>

<script>
import customCheckbox from "@/components/common/custom-checkbox.vue"
export default {
    components: {
        customCheckbox,
    },
    props: {
        productInfo: {
            type: Object,
            default: {},
        },
        isShowCheckBox: {
            type: Boolean,
            default: true,
        },
        specshow: {
            type: Boolean,
            default: true,
        },
        orderType: {
            type: Number,
            default: -1,
        },
        isEdit: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            isSelect: false,
            subIds: [],
            tagName: "折叠",
        }
    },
    mounted() {
        //
    },
    methods: {
        select() {
            // this.specshow = !this.specshow
            this.$emit("specfn", !this.specshow)
        },
        change(isSelect) {
            let obj = {
                isSelect: !isSelect,
                proId: this.productInfo.ProductId,
                subIds: this.subIds,
                warehouseId: this.productInfo.WarehouseId,
            }
            // 编辑状态下不管是否开启库存验证，都不验证库存
            if (this.isEdit) {
                this.$emit("changeCheck", obj)
            } else {
                if (this.orderType == 24) {
                    this.$emit("changeCheck", obj)
                } else {
                    // 非编辑状态下，如果不验证库存
                    if (this.getAppSet().NoCheckStock) {
                        this.$emit("changeCheck", obj)
                    } else {
                        // 如果验证库存
                        let subIds = []
                        this.productInfo.SubItems.forEach((e) => {
                            if (e.Amount <= e.Stock) {
                                subIds.push(String(e.ID))
                            }
                        }) //有一个规格库存不足时无法全选
                        if (subIds.length == this.productInfo.SubItems.length) {
                            this.$emit("changeCheck", obj)
                        } else {
                            this.easyToast("库存不足")
                        }
                    }
                }
            }

            // console.log("this.productInfo:", this.productInfo)
            // let obj = {
            //     isSelect: !isSelect,
            //     proId: this.productInfo.ProductId,
            //     subIds: this.subIds,
            //     warehouseId: this.productInfo.WarehouseId,
            // }
            // this.$emit("changeCheck", obj)
            // if (this.isEdit) {
            //     //库存不足是不能选择 编辑状态可选择
            //     let obj = {
            //         isSelect: !isSelect,
            //         proId: this.productInfo.ProductId,
            //         subIds: this.subIds,
            //     }
            //     this.$emit("changeCheck", obj)
            // } else {
            //     let subIds = []
            //     this.productInfo.SubItems.forEach((e) => {
            //         if (!this.getAppSet().NoCheckStock && this.isEdit) {
            //             if (e.Amount <= e.Stock) {
            //                 subIds.push(String(e.ID))
            //             }
            //         }
            //     }) //有一个规格库存不足时无法全选
            //     if (subIds.length == this.productInfo.SubItems.length) {
            //         let obj = {
            //             isSelect: !isSelect,
            //             proId: this.productInfo.ProductId,
            //             subIds: this.subIds,
            //         }
            //         this.$emit("changeCheck", obj)
            //     }
            // }
        },
        getIsSelect(is) {
            return is
        },
        // 进入商品详情
        goDetailPage() {
            if (this.getAppSet().isHideProDetail) {
                return
            }
            if (this.getAppSet().pagesClassify) {
                if (this.orderType == 24) {
                    this.easyGoTo(
                        `/pages_classify/packet/product/productDetail?id=${this.productInfo.ProductId}&InfoType=6&wareHouseId=${this.productInfo.WarehouseId}`,
                    )
                } else {
                    this.easyGoTo(
                        `/pages_classify/packet/product/productDetail?id=${this.productInfo.ProductId}&InfoType=${this.productInfo.SkuType ? this.productInfo.SkuType : 1
                        }`,
                    )
                }
            } else {
                if (this.orderType == 23) {
                    this.easyGoTo(
                        `/pages_shop/packet/product/productDetail?id=${this.productInfo.ProductId}&InfoType=${this.productInfo.SkuType ? this.productInfo.SkuType : 1
                        }&orderType=${this.orderType}`,
                    )
                } else {
                    this.easyGoTo(
                        `/pages_shop/packet/product/productDetail?id=${this.productInfo.ProductId}&InfoType=${this.productInfo.SkuType ? this.productInfo.SkuType : 1
                        }`,
                    )
                }
            }
        },
    },
}
</script>

<style lang="scss">
.cart-item-product {
    display: flex;
    flex-direction: row;
    align-items: center;
    border-bottom: solid 1rpx $uni-bg-color-grey;
    padding: $app-page-padding 0;
    position: relative;

    .item-radio {
        display: flex;
        align-items: center;
        margin-right: 20rpx;
    }

    .item-img {
        width: 120rpx;
        height: 120rpx;
        margin-right: 20rpx;
        border-radius: 8rpx;
        flex-shrink: 0;
    }

    .item-name {
        display: flex;
        flex: 1;
        flex-direction: column;
        font-weight: 700;
        font-size: $font-size-28;
        word-break: break-word;
    }
}

.oneSpec {
    border-bottom: none;
    padding: $app-page-padding 0 10rpx;

    .item-radio {
        margin-right: 36rpx;
        margin-left: 12rpx;
    }
}

.unit-btn {
    position: absolute;
    right: 0;
    bottom: 24rpx;
    width: 80rpx;
    height: 32rpx;
    background: #ffffff;
    border-radius: 20rpx;
    border: 1rpx solid #b9c0d0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20rpx;
    color: #333;

    .unit-text {
        margin-right: 10rpx;
    }

    .arrow {
        border: solid $color-gray-3;
        border-width: 0 1px 1px 0;
        padding: 2px;
    }

    .arrow-up {
        margin-top: 8rpx;
    }

    .arrow-down {
        margin-bottom: 5rpx;
    }
}
</style>
